import {createStore} from "vuex";

const demoUsers = {
    bingo: "??12345a",
    admin: "admin",
    test: "test123"
}
const Store = createStore({
    state() {
        return {
            userName: "",
            userPassword: "",
            demoUsers: demoUsers
        }
    },
    getters: {
        isLogin(state) {
            return state.userName.length > 0
        }
    },
    mutations: {
        clearUserInfo: (state) => {
            state.userName = ""
            state.password = ""
        },
        loginUser: (state, payload) => {
            let username = payload.username;
            let password = payload.password;
            // eslint-disable-next-line no-prototype-builtins
            if (!state.demoUsers.hasOwnProperty(username)) {
                return
            }
            if (password !== state.demoUsers[username]) {
                return
            }
            state.userName = username
            state.userPassword = password
        }
    }
})
export default Store;
